package cn.akira.domain.strategy.repository;

import cn.akira.domain.strategy.model.entity.StrategyAwardEntity;
import cn.akira.domain.strategy.model.entity.StrategyEntity;
import cn.akira.domain.strategy.model.entity.StrategyRuleEntity;
import cn.akira.domain.strategy.model.vo.RuleTreeVO;
import cn.akira.domain.strategy.model.vo.StrategyAwardRuleModelVO;
import cn.akira.domain.strategy.model.vo.StrategyAwardStockKeyVO;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @author fjl95
 * @date 2025/5/11
 * @description 策略 仓储实现
 */
public interface IStrategyRepository {
    List<StrategyAwardEntity> queryStrategyAwardList(Long strategyId);

    /*
    存储随机数-奖品对应表到redis
     */
    void storeStrategyAwardSearchRateTable(String key, BigDecimal rateRange, Map<Integer,Integer> shuffleStrategyAwardSearchRateTables);

    /*
    查询随机数对应的奖品
     */
    Integer getStrategyAwardAssemble(String key, Integer randomKey);

    /*
    查询随机数范围
     */
    int getRateRange(String key);


    StrategyEntity queryStrategyEntityByStrategyId(Long strategyId);

    StrategyRuleEntity queryStrategyRule(Long strategyId, String ruleModel);

    String queryStrategyRuleValue(Long strategyId, Integer awardId, String ruleModel);
    String queryStrategyRuleValue(Long strategyId, String ruleModel);
    StrategyAwardRuleModelVO queryStrategyAwardRuleModelVO(Long strategyId, Integer awardId);
    /**
     * 根据规则树ID，查询树结构信息
     *
     * @param treeId 规则树ID
     * @return 树结构信息
     */
    RuleTreeVO queryRuleTreeVOByTreeId(String treeId);

    /**
     * 缓存奖品库存
     * @param cacheKey
     * @param awardCountSurplus
     */
    void cacheStrategyAwardCount(String cacheKey, Integer awardCountSurplus);

    /**
     * 库存扣减操作
     * @param cacheKey
     * @return
     */
    Boolean subtractionAwardStock(String cacheKey, Date endDateTime);

    void awardStockConsumeSendQueue(StrategyAwardStockKeyVO build);

    StrategyAwardStockKeyVO takeQueueValue();

    void updateStrategyAwardStock(Long strategyId, Integer awardId);

    StrategyAwardEntity queryStrategyAwardEntity(Long strategyId, Integer awardId);

    Long queryStrategyIdByActivityId(Long activityId);

    Integer queryTodayUserRaffleCount(String userId, Long strategyId);

    Map<String, Integer> queryAwardRuleLockCount(String[] treeIds);

    Integer queryActivityAccountTotalUseCount(String userId, Long strategyId);

}
